package com.juyu.miliao.common.util;

import java.io.IOException;
import javax.servlet.http.Part;

import com.juyu.miliao.common.util.oss.OSSConfig;
import com.juyu.miliao.common.util.oss.OSSUtil;

public enum UpLoadFile {
	INSTANCE;

	public String uploadClassifyImg2WSCDN(OSSConfig ossConfig, Part uploadFile) throws IOException, Exception {
		String exten = uploadFile.getSubmittedFileName().substring(uploadFile.getSubmittedFileName().lastIndexOf("."));
		String fileName = UUIDUtil.getUUID() + exten;
		String savePath = "miliao/";
		if(exten.toLowerCase().contains("jpg") ||exten.toLowerCase().contains("png")
				||exten.toLowerCase().contains("jpeg") ||exten.toLowerCase().contains("gif")){
			savePath +="photos/"; //图像 
		}else{
			savePath +="voice/"; // 语音
		}
		return ossConfig.getAccessUrl() + OSSUtil.putObject(ossConfig, uploadFile, savePath + fileName);
	}
}
